//
//  DayNightLabel.m
//  one·一个  tyw
//
//  Created by tyw on 15/8/27.
//  Copyright (c) 2015年 tyw. All rights reserved.
//

#import "DayNightLabel.h"
#import "DayNightManager.h"

@implementation DayNightLabel


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        //接收通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayNightNotification:) name:kDayNightTypeChangedNotification object:nil];
    }
    return self;
}

- (void)awakeFromNib {
    //添加通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayNightNotification:) name:kDayNightTypeChangedNotification object:nil];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kDayNightTypeChangedNotification object:nil];
}

- (void)loadLabelColor {
    DayNightManager* manager = [DayNightManager sharedManager];
    
    NSString* currentType = [manager getCurrentDayNightType];
    if ([currentType isEqualToString:kDayNightCurrentTypeIsDay]) {      //是日间
        self.textColor = [UIColor blackColor];
    } else {                                                    //是夜间
        self.textColor = [UIColor lightGrayColor];
    }
}

//接收到通知后调用的方法，日间夜间模式切换，改变文本字体颜色
- (void)dayNightNotification:(NSNotification*)notification {
//    NSLog(@"notification.object  %@", notification.object);
    
    if ([notification.object isEqualToString:kDayNightCurrentTypeIsDay]) {     //如果切换到了日间模式
        self.textColor = [UIColor blackColor];
    } else if ([notification.object isEqualToString:kDayNightCurrentTypeIsNight]) {        //如果切换到了夜间模式
        self.textColor = [UIColor lightGrayColor];
    } else {
        NSLog(@"日间夜间模式 通知发送 不正确");
    }
}


@end
